
package com.noah.project.dao

import com.noah.project.model.Company
import org.apache.ibatis.annotations.Delete
import org.apache.ibatis.annotations.Insert
import org.apache.ibatis.annotations.Select
import org.apache.ibatis.annotations.Update
import org.springframework.stereotype.Repository

@Repository
interface CompanyDao {
    @Insert("INSERT INTO company (aid, position, company, workStart, workEnd) " +
            "VALUES(#{aid}, #{position}, #{company}, #{workStart}, #{workEnd})")
    fun insert(company: Company): Long

    @Delete("DELETE FROM company WHERE coid = #{coid}")
    fun delete(coid: Long?): Long

    @Delete("DELETE FROM company WHERE aid = #{aid}")
    fun deleteAll(aid: Long?): Long

    @Update("UPDATE company SET " +
            "company = #{company}," +
            "position = #{position}," +
            "workStart = #{workStart}," +
            "workEnd = #{workEnd}" +
            " WHERE coid = #{coid}")
    fun update(company: Company): Long

    @Select("SELECT * FROM company WHERE coid = #{coid}")
    fun findCompany(coid: Long?): Company?

    @Select("SELECT * FROM company WHERE aid = #{aid}")
    fun findCompanies(aid: Long?): List<Company>
}
